<%--
  Created by IntelliJ IDEA.
  User: Gao
  Date: 2023/7/27
  Time: 13:36
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
    <form id="formId" method="post">
        用户名：<input type="text" name="name"/><br/>
        年龄：<input type="text" name="age"/><br/>
        性别：<input type="text" name="gender"/><br/>
        班级：
        <select id="banjiId" name="banjiId">
            <option>---请选择班级---</option>
        </select>
        <br/>
        <input type="button" onclick="submitForm()" value="添加"/>
    </form>

    <script src="<%=request.getContextPath()%>/static/jquery-2.1.4.js" type="text/javascript" charset="utf-8"></script>
    <script src="<%=request.getContextPath()%>/static/layer/layer.js" type="text/javascript" charset="utf-8"></script>
    <script src="<%=request.getContextPath()%>/static/mylayer.js" type="text/javascript" charset="utf-8"></script>
    <script>
        $(function() {
            $.post(
                '<%=request.getContextPath()%>/banji?method=selectAll',
                function(result) {
                    console.log(result);
                    if (result.code == 0) {
                        $(result.data).each(function() {
                            $('#banjiId').append('<option value="'+this.id+'">'+this.name+'</option>');
                        });
                    }
                },
                'json'
            );
        });

        function submitForm() {
            $.post(
                '<%=request.getContextPath()%>/student?method=add',
                $('#formId').serialize(),
                function(result) {
                    console.log(result);
                    if (result.code == 0) {
                        mylayer.okUrl(result.msg, '<%=request.getContextPath()%>/student?method=selectAll');
                    } else {
                        mylayer.errorMsg(result.msg);
                    }
                },
                'json'
            );
        }
    </script>
</body>
</html>
